package no.doomsday.scripting.simplescriptengine 
{
	import flash.events.EventDispatcher;
	import flash.events.TimerEvent;
	import flash.utils.describeType;
	import flash.utils.Dictionary;
	import flash.utils.Timer;
	import no.doomsday.scripting.simplescriptengine.commands.ScriptCommand;
	import no.doomsday.scripting.simplescriptengine.interfaces.IScriptExecutor;
	import no.doomsday.scripting.simplescriptengine.scriptevents.IScriptExecutable;
	/**
	 * ...
	 * @author Andreas Rønning (andreas@doomsday.no)
	 */
	public class ScriptEngine
	{
		private static var _core:IScriptExecutor;
		public function ScriptEngine() 
		{
			throw new Error("Use static methods");
		}
		/**
		 * Creates a new instance of the script core and prepares for use
		 */
		public static function initialize():void {
			if (!_core) {
				_core = new ScriptCore();
			}
		}
		/**
		 * Takes a script as a string and executes it
		 * @param	script
		 */
		public static function run(script:String):void {
			if (_core)_core.run(script);
		}
		/**
		 * Loads a script from an url and executes it when loaded
		 * @param	scriptURL
		 */
		public static function loadAndRun(scriptURL:String):void {
			if (_core)_core.loadAndRun(scriptURL);
		}
		/**
		 * Maps an invoker string to a callback
		 * @param	invoker
		 * The script function name
		 * @param	callback
		 * The callback it should refer to
		 */
		public static function mapCommand(invoker:String, callback:Function):void {
			if (_core)_core.mapCommand(invoker, callback);
		}
		/**
		 * If the script has caused the script to he paused with "wait()",
		 * call resume to continue. This is specifically to allow scripts to have delayed completion
		 */
		public static function resume():void {
			if (_core)_core.resume();
		}
		
		/**
		 * Exposes an object's public properties to the script engine
		 * @param	obj
		 */
		static public function expose(obj:Object):void
		{
			if (_core)_core.expose(obj);
		}
		public static function get lastReturnValue(): * {
			if (_core) {
				return _core.lastReturnValue;
			}
		}
		
	}

}